//LiuZh 2017-06-27
import React, {Component} from 'react';
import {
    View,
    Image,
    Dimensions,
    TouchableWithoutFeedback,
    StyleSheet,
    Text,
    TouchableOpacity,
    TextInput,
    ScrollView
} from 'react-native';

let winWidth = Dimensions.get('window').width;//屏幕宽度

//alert('winWidth:'+winWidth);

import InitDB from '../../../core/database/init-db';
import Constant from '../../../core/constant/constant.js';
import ToastUtil from '../../../core/utils/toast-util.js';
import Color from '../../../core/constant/color.js';
import {Loading, EasyLoading} from 'react-native-easy-loading';

//import {CachedImage} from "react-native-img-cache";
// <CachedImage source={{ uri: this.state.image_}} mutable />

export default class LoginScene extends Component {

    constructor(props) {
        super(props);
        this.state = {
            loading: false,
            image_: '',
        }
    }

    render() {
        /*if(this.state.loading){
            return (
                <View>
                    <Text>正在加载...</Text>>
                    </View>
            )

        }*/

        //alert(image_);
        //image_='https://i0.wp.com/inews.gtimg.com/newsapp_match/0/1011414067/0';
        /*if (this.state.loading) {
            return (<View style={styles.body}>
                <Loading />
            </View>);
        } else {*/
        return (
            <View style={styles.body}>
                <Loading/>
                <ScrollView>
                    <Image resizeMode={Image.resizeMode.stretch} style={{width: winWidth, height: winWidth * 265 / 75}}
                           source={{uri: this.state.image_}} onLoad={this._onload.bind(this)}/>
                </ScrollView>

            </View>
        )


    };

    componentDidMount() {
        Promise.resolve().then(EasyLoading.show('loading....', 10000));
        let images = InitDB.getShequnsiweiImage();
        let image_ = Constant.serverUrl + images[0].IMAGE_;
        //alert(image_);
        this.setState({
            loading: false,
            image_: image_
        })
    }

    _onload() {
        Promise.resolve().then(EasyLoading.dismis());
    }
}

const styles = StyleSheet.create({
    body: {
        backgroundColor: '#FFF',
        flex: 1,
        alignItems: 'center',
    },
    topBg: {
        width: winWidth,
        height: winWidth / 5 * 3,
        justifyContent: 'center',
        alignItems: 'center',
        marginBottom: 40,
    },
    loginText: {
        fontSize: 18,
        color: '#FFF',
        position: 'absolute',
        top: 10,
    },
    inputBox: {
        flexDirection: 'row',
        height: 40,
        marginLeft: 40,
        marginRight: 40,
        marginTop: 10,
        borderColor: '#DDD',
        borderRadius: 8,
        borderWidth: 1,
        justifyContent: 'center',
        alignItems: 'center',
    },
    icon: {
        height: 15,
        width: 15,
        marginLeft: 10,
        marginRight: 10,
    },
    pwdBox: {
        height: 20,
        marginTop: 10,
        flexDirection: 'row',
        paddingLeft: 5,
        paddingRight: 5,
        marginLeft: 40,
        marginRight: 40,
    },
    hintText: {
        fontSize: 12,
        color: '#999',
        padding: 0,
    },
    inputText: {
        flex: 1,
        marginRight: 10,
    },
    loginBtn: {
        height: 40,
        borderRadius: 8,
        backgroundColor: '#00F',
        marginRight: 40,
        marginLeft: 40,
        marginTop: 40,
        justifyContent: 'center',
        alignItems: 'center',
    },
    btnText: {
        fontSize: 15,
        color: '#FFF',
    }
});
